home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / suntar1.cpt / select button.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-10  |  2.8 KB  |  83 lines

  1. /*-----------------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Collection of Utilities for DTS Sample code
  6. #
  7. #    Program:    Utilities.c.o
  8. #    File:        Utilities.c    -    C Source
  9. #
  10. #    Copyright ⌐ 1988-1990 Apple Computer, Inc.
  11. #    All rights reserved.
  12. #
  13. -----------------------------------------------------------------------------------------*/
  14. /* Given the button control handle, this will cause the button to look as if it
  15.    has been clicked in. This is nice to do for the user if they type return or
  16.    enter to select the default item. */
  17.  
  18. #define kDelayTime                8            /* For the delay time when flashing the
  19.                                                menubar and highlighting a button.
  20.                                                8/60ths of a second*/
  21. #define kSelect                    1            /* select the control */
  22. #define kDeselect                0            /* deselect the control */
  23.  
  24. void SelectButton(ControlHandle);
  25. void OutlineControl(ControlHandle);
  26.  
  27. void    SelectButton(ControlHandle button)
  28. {
  29.     long            finalTicks;
  30.  
  31.     HiliteControl(button, kSelect);
  32.     Delay(kDelayTime, &finalTicks);
  33.     HiliteControl(button, kDeselect);
  34. }
  35.  
  36. /* Given any control handle, this will draw an outline around it.  This is used
  37.   for the default button of a window.  The extra nice feature here is that I╒ll
  38.   erase the outline for buttons that are inactive.  Seems like there should be
  39.   a Toolbox call for getting a control╒s hilite state. Since there isn╒t, I have
  40.   to look into the control record myself. This should be called for update and
  41.   activate events.
  42.  
  43.   The method for determining the oval diameters for the roundrect is a little
  44.   different than that recommended by Inside Mac. IM I-407 suggests that you
  45.   use a hardcoded (16,16) for the diameters. However, this only looks good for
  46.   small roundrects. For larger ones, the outline doesn╒t follow the inner
  47.   roundrect because the CDEF for simple buttons doesn╒t use (16,16). Instead,
  48.   it uses half the height of the button as the diameter. By using this
  49.   formula, too, our outlines look better.
  50.  
  51.   WARNING: This will set the current port to the control╒s window. */
  52.  
  53. #define NULL 0L
  54. #define kButtonFrameInset    -4
  55. #define kButtonFrameSize    3
  56.  
  57. void        OutlineControl(ControlHandle button)
  58. {
  59.     Rect        theRect;
  60.     PenState    curPen;
  61.     short        buttonOval;
  62.  
  63.     if ( button != NULL ) {
  64.         SetPort((**button).contrlOwner);
  65.         GetPenState(&curPen);
  66.         PenNormal();
  67.         theRect = (**button).contrlRect;
  68.         InsetRect(&theRect, kButtonFrameInset, kButtonFrameInset);
  69.         buttonOval = (theRect.bottom - theRect.top) / 2;
  70. #if 0
  71. #ifdef applec
  72.         PenPat((**button).contrlHilite == kCntlActivate ? &qd.black : &qd.gray);
  73. #else
  74.         PenPat((**button).contrlHilite == kCntlActivate ? &black : &gray);
  75. #endif
  76. #endif
  77.         PenSize(kButtonFrameSize, kButtonFrameSize);
  78.         FrameRoundRect(&theRect, buttonOval, buttonOval);
  79.         SetPenState(&curPen);
  80.     }
  81. }
  82.  
  83.